package app.auto.runner.base.utility;

import android.app.Activity;
import android.util.Log;
import android.widget.Toast;


import app.auto.runner.base.intf.FunCallback;
import app.auto.runner.base.intf.json.JsonToMapUtils;

/**
 * Created by Administrator on 2017/11/11.
 */
public class ToastUtil {
    public static ToastUtil live(Activity aty) {
        return new ToastUtil(aty);
    }

    public static boolean toastenable = true;
    Activity act;

    public ToastUtil(Activity act) {
        this.act = act;
    }

    public void toast(Object toast) {
        toast(toast, "");
    }

    public void toast(Object toast, String tag) {
        if (!toastenable) return;
        String show = "";
        if (toast instanceof String) {
            show = toast.toString();
        } else {
            show = JsonToMapUtils.entityToJson(toast);
        }
        final String finalShow = show;
        HandlerUtil.sendEmptymessage(act, new FunCallback() {
            @Override
            public void simpleRun(Object aty) {
                super.simpleRun(aty);
                Toast.makeText(act, finalShow, Toast.LENGTH_SHORT).show();
            }
        });
        Log.d(act.getClass().getSimpleName(), show);
        if (tag.equals("umeng")) {
        }
    }
}
